package com.datastructure.test.iscontaintree;

public class IsContainTree {

    public static void main(String[] args) {

    }

    public boolean isContains (TreeNode root1, TreeNode root2) {
        // write code here
        if(root1==null){
            return false;
        }
        if(root2==null){
            return true;
        }
        if(root1.val== root2.val){
            return computeIsContains(root1,root2);
        }
        return isContains(root1.left,root2)||isContains(root1.right,root2);
    }

    private boolean computeIsContains(TreeNode root1, TreeNode root2) {
        if(root1 == null&&root2!=null){
            return false;
        }
        if(root2 == null&&root1!=null){
            return false;
        }
        if(root1 == null){
            return true;
        }
        return root1.val == root2.val && computeIsContains(root1.left, root2.left) && computeIsContains(root1.right, root2.right);
    }
}

class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
}
